package java.awt;


import java.awt.AWTException;
import java.awt.BufferCapabilities;
import java.awt.Canvas;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import javax.accessibility.*;


public class Canvas extends Component implements Accessible {

    private BufferedImage canvasImage = null;
    private Graphics canvasGraphics = null;

    public Canvas() {
        canvasImage = new BufferedImage(765, 503, BufferedImage.TYPE_INT_RGB);
        canvasGraphics = canvasImage.getGraphics();
    }

    public Canvas(GraphicsConfiguration graphicsconfiguration) {
        this();
        graphicsConfig = graphicsconfiguration;
    }

    public Graphics getGraphics() {
        Thread.yield();
        getCanvasGraphics().drawImage(canvasImage, 0, 0, null);
        return (canvasGraphics = canvasImage.createGraphics());
    }

    public Graphics getCanvasGraphics() {
        return super.getGraphics();
    }

    public void setLocation(int x, int y) {
        super.setLocation(0, 0);
    }

    String constructComponentName() {
        return base + nameCounter++;
    }

    public void addNotify() {
        synchronized (getTreeLock()) {
            if (peer == null)
                peer = getToolkit().createCanvas(this);
            super.addNotify();
        }
    }

    public void paint(Graphics g) {
        g.clearRect(0, 0, width, height);
        System.out.println("Painting");
    }

    public void update(Graphics g) {
        g.clearRect(0, 0, width, height);
        paint(g);
    }

    boolean postsOldMouseEvents() {
        return true;
    }

    public void createBufferStrategy(int i) {
        super.createBufferStrategy(i);
    }

    public void createBufferStrategy(int i, BufferCapabilities buffercapabilities) throws AWTException {
        super.createBufferStrategy(i, buffercapabilities);
    }

    public BufferStrategy getBufferStrategy() {
        return super.getBufferStrategy();
    }

    public AccessibleContext getAccessibleContext() {
        if (accessibleContext == null)
            accessibleContext = new AccessibleAWTCanvas();
        return accessibleContext;
    }

    private static final String base = "canvas";
    private static int nameCounter = 0;
    private static final long serialVersionUID = 0xe04a7a764a4bce12L;

    protected class AccessibleAWTCanvas extends Component.AccessibleAWTComponent {

        public AccessibleRole getAccessibleRole() {
            return AccessibleRole.CANVAS;
        }

        private static final long serialVersionUID = 0xa836fb5a1f61df35L;
        final Canvas this$0;

        protected AccessibleAWTCanvas() {
            super();
            this$0 = Canvas.this;
        }
    }

}